//
// Created by Eric on 2022/11/5.
// 这个类只负责持有文明的数据
//

#ifndef UUU_CIVILIZATION_H
#define UUU_CIVILIZATION_H
#include "Event.h"
#include <random>

class Civilization {
public:
    // 构造方法
    // 静态工厂方法，创建始祖文明
    static Civilization CreateInitialCivilization(int idx, string name, int technology_level, int military_level, int energy, double warlike, int intelligence);
    Civilization();

public:
    void Display(){
        cout <<"idx: "<< idx_<<endl;
        cout << "name: " << name_ <<endl;
        cout << "asobject_known: " << asobject_known_ << endl;
        cout << "technology_level: "  <<technology_level_ <<endl;
        cout << "military_level: "<< military_level_ <<endl;
        cout << "energy: " <<energy_ <<endl;
        cout<<"warlike: " <<warlike_ <<endl;
        cout << "intelligence: "  <<intelligence_ <<endl;
    }



    // api
    /**
     * @param ahs 用于比较的文明
     * @return 若当前文明科技水平落后返回true，否则返回false。
     */
    [[nodiscard]] bool TechnologyLagBehind(const Civilization& ahs) const{
        return this->technology_level_ < ahs.technology_level_;
    }

    // 用于比较
    [[nodiscard]] bool MilitaryLagBehind(const Civilization& ahs)const{
        return this->military_level_ < ahs.military_level_;
    }

public:
    // getter & setter
    [[nodiscard]] int idx() const{return this->idx_;}
    [[nodiscard]] int asobject_known() const{return this->asobject_known_;}
    [[nodiscard]] const std::vector<Event>& agenda() const{return this->agenda_;}

    [[nodiscard]] int combat_effectiveness() const{
        return warlike_ * 100.0 + military_level_ * 0.7 + technology_level_ * 0.3;
    }
    [[nodiscard]] int technology_level()const{return this->technology_level_;}
    [[nodiscard]] int military_level()const{return military_level_;}
    [[nodiscard]] int energy()const {return energy_;}
    int mother_aso_idx() const{return mother_planet_idx_;}

    // setter函数
    void set_asobject_known(int civilization_known) { asobject_known_ = civilization_known;}
    void set_technology_level(int technology_level){technology_level_  = technology_level;}
    void set_military_level(int military_level){military_level_ = military_level;}
    void set_energy(int energy){energy_ = energy;}

    /**
     *
     * @return [0.01, 1]
     */
    [[nodiscard]] double warlike() const{return this->warlike_;}

    [[nodiscard]] int intelligence() const{return intelligence_;}

private:
    // data
    // 连接外部参数
    int idx_;
    int mother_planet_idx_;
    string name_;
    int asobject_known_;
    std::vector<Event> agenda_;


    // 文明发展参数
    int technology_level_;
    int military_level_;
    int energy_;

    // 文明个性参数
    double warlike_;
    int intelligence_;
};

Civilization::Civilization() {
    idx_ = -1;
    mother_planet_idx_ = -1;
    asobject_known_ = 0;
    agenda_ = std::vector<Event>();

    technology_level_ = 0;
    military_level_ = 0;
    energy_ = 0;

    warlike_ = 0;
    intelligence_ = 0;
}

// 创建一个始祖文明
Civilization
Civilization::CreateInitialCivilization(int idx,string name, int technology_level, int military_level, int energy, double warlike,
                                        int intelligence) {
    Civilization product;
    product.idx_ = idx;
    product.mother_planet_idx_ = idx; // 初始文明的母星idx和文明idx相同，但是新创建的文明就不能这么做了
    product.name_ =  std::move(name);
    product.technology_level_ = technology_level;
    product.military_level_ = military_level;
    product.energy_ = energy;
    product.warlike_ = warlike;
    product.intelligence_ = intelligence;
    return product;
}

#endif //UUU_CIVILIZATION_H
